<template>
  <div class="common-head">
    <van-nav-bar
      :title="title"
      left-arrow
      @click-left="$router.go(-1)"
    >
      <template #right>
        <van-icon v-if="$route.path == '/user'" name="cross" size="22" @click="Del"/>
        <van-icon v-else name="search" size="22" @click="$router.push('/search')" />
      </template>
    </van-nav-bar>
  </div>
</template>

<script>
import { delToken } from '_utils'
export default {
  props: {
    title: {
      type: String,
      required: true
    }
  },
  methods: {
    Del () {
      this.$dialog.confirm({
        message: '您确定退出登录嘛'
      })
        .then(() => {
          delToken()
          this.$router.go(0)
        })
        .catch(() => {
          return ''
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.common-head{
  height: 50px;
  position: fixed;
  width: 100%;
  left: 0;
  top: 0;
  z-index: 100;
  /deep/ .van-nav-bar{
    .van-icon{
      color: #787878;
      font-size: 22px
    }
  }
}
</style>
